{% extends 'base.html' %}

{% block title %}
管理赛事配额 - {{ event.name }}
{% endblock %}

{% block content %}
<div class="container mt-5">
    <h2 class="text-center mb-4">管理赛事配额 - {{ event.name }}</h2>

    <div class="row justify-content-center mb-5">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    添加日期配额
                </div>
                <div class="card-body">
                    <form method="POST">
                        {{ form.hidden_tag() }}

                        <div class="mb-3">
                            {{ form.date.label(class="form-label") }}
                            {{ form.date(class="form-control") }}
                            {% for error in form.date.errors %}
                                <div class="text-danger">{{ error }}</div>
                            {% endfor %}
                        </div>

                        <div class="mb-3">
                            {{ form.quota.label(class="form-label") }}
                            {{ form.quota(class="form-control") }}
                            {% for error in form.quota.errors %}
                                <div class="text-danger">{{ error }}</div>
                            {% endfor %}
                        </div>

                        <div class="text-center">
                            {{ form.submit(class="btn btn-primary") }}
                            <a href="{{ url_for('admin') }}" class="btn btn-secondary ms-3">返回</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="row justify-content-center">
        <div class="col-md-10">
            <h3 class="text-center mb-4">现有日期配额</h3>
            <table class="table table-bordered table-hover">
                <thead class="table-dark">
                    <tr>
                        <th>日期</th>
                        <th>配额</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% if date_quotas %}
                        {% for quota in date_quotas %}
                        <tr>
                            <td>{{ quota.date.strftime('%Y-%m-%d') }}</td>
                            <td>{{ quota.quota }}</td>
                            <td>
                                <a href="{{ url_for('delete_quota', quota_id=quota.id) }}" class="btn btn-danger btn-sm" onclick="return confirm('确定要删除吗？')">删除</a>
                            </td>
                        </tr>
                        {% endfor %}
                    {% else %}
                        <tr>
                            <td colspan="3" class="text-center">暂无自定义日期配额，将使用默认配额：{{ event.quota }}</td>
                        </tr>
                    {% endif %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}